cmake_minimum_required(VERSION 3.13)
project(TuGraph C CXX)

set(LGRAPH_API_SRC 
        ${CMAKE_SOURCE_DIR}/src/lgraph_api/olap_base.cpp
        ${CMAKE_SOURCE_DIR}/src/lgraph_api/lgraph_utils.cpp
        ${CMAKE_SOURCE_DIR}/src/lgraph_api/olap_profile.cpp)

function(add_standalone APP)
    add_executable(${APP}_standalone algo_cpp/${APP}_core.cpp algo_cpp/${APP}_standalone.cpp ${LGRAPH_API_SRC})
    target_link_libraries(${APP}_standalone ${Boost_LIBRARIES} libstdc++fs.a libgomp.a dl)
    set_target_properties( ${APP}_standalone PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
    target_include_directories(${APP}_standalone PUBLIC ${CMAKE_SOURCE_DIR}/include
                                                        ${CMAKE_SOURCE_DIR}/src)
endfunction()

function(add_embed APP)
    add_executable(${APP}_embed algo_cpp/${APP}_core.cpp algo_cpp/${APP}_procedure.cpp embed_main.cpp)
    target_link_libraries(${APP}_embed ${Boost_LIBRARIES} lgraph libgomp.a crypto dl)
    set_target_properties( ${APP}_embed PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
endfunction()

function(add_embed2 APP)
    add_executable(${APP}_embed algo_cpp/${APP}.cpp embed_main.cpp)
    target_link_libraries(${APP}_embed ${Boost_LIBRARIES} lgraph libgomp.a crypto dl)
    set_target_properties( ${APP}_embed PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
    target_include_directories(${APP}_embed PUBLIC ${CMAKE_SOURCE_DIR}/include)
endfunction()

function(add_extension APP)
    add_cython_target(${APP} algo_cython/${APP}_procedure.py CXX)
    add_library(${APP} MODULE ${APP})
    python_extension_module(${APP})
    target_link_libraries(${APP} ${Boost_LIBRARIES} lgraph libgomp.a dl)
    set_target_properties( ${APP} PROPERTIES
            LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
endfunction()

function(add_v2procedure APP)
    add_library(${APP}_v2 SHARED algo_cpp/${APP}_core.cpp algo_cpp/${APP}_procedure_v2.cpp)
    target_link_libraries(${APP}_v2 ${Boost_LIBRARIES} lgraph libgomp.a crypto)
    set_target_properties( ${APP}_v2 PROPERTIES
            LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
endfunction()

function(add_standalone_from_community APP)
    add_executable(${APP}_standalone community/${APP}_core.cpp community/${APP}_standalone.cpp ${LGRAPH_API_SRC})
    target_link_libraries(${APP}_standalone ${Boost_LIBRARIES} libstdc++fs.a libgomp.a dl)
    set_target_properties( ${APP}_standalone PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/algo")
    target_include_directories(${APP}_standalone PUBLIC ${CMAKE_SOURCE_DIR}/include
                                                        ${CMAKE_SOURCE_DIR}/src)
endfunction()

add_standalone(apsp)
add_standalone(bfs)
add_standalone(pagerank)
add_standalone(sssp)
add_standalone(wcc)
add_standalone(lcc)
add_standalone(lpa)
add_standalone(bc)
add_standalone(dc)
add_standalone(de)
add_standalone(en)
add_standalone(ji)
add_standalone(clce)
add_standalone(cn)
add_standalone(kcore)
add_standalone(hits)
add_standalone(triangle)
add_standalone(fast_triangle_counting)
add_standalone(louvain)
add_standalone(motif)
add_standalone(mssp)
add_standalone(scc)
add_standalone(spsp)
add_standalone(ktruss)
add_standalone(kcliques)
add_standalone(locate_cycle)
add_standalone(ppr)
add_standalone(wpagerank)
add_standalone(mis)
add_standalone(trustrank)
add_standalone(slpa)
add_standalone(wlpa)
add_standalone(subgraph_isomorphism)
add_standalone(sybilrank)
add_standalone(leiden)
add_standalone_from_community(khop)

add_embed(apsp)
add_embed(bfs)
add_embed(pagerank)
add_embed(sssp)
add_embed(wcc)
add_embed(lcc)
add_embed(lpa)
add_embed(bc)
add_embed(dc)
add_embed(de)
add_embed(en)
add_embed(ji)
add_embed(clce)
add_embed(cn)
add_embed(kcore)
add_embed(hits)
add_embed(triangle)
add_embed(fast_triangle_counting)
add_embed(louvain)
add_embed(motif)
add_embed(mssp)
add_embed(scc)
add_embed(spsp)
add_embed(ktruss)
add_embed(kcliques)
add_embed(locate_cycle)
add_embed(ppr)
add_embed(wpagerank)
add_embed(mis)
add_embed(trustrank)
add_embed(slpa)
add_embed(wlpa)
add_embed(subgraph_isomorphism)
add_embed(sybilrank)
add_embed(leiden)

add_embed2(khop_kth)
add_embed2(khop_within)
add_embed2(feature_float)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/src/cython/)
find_package(PythonInterp 3)
find_package(PythonExtensions REQUIRED)
find_package(Cython REQUIRED)
set(CYTHON_FLAGS " -I${CMAKE_SOURCE_DIR}/src/cython/ -I${CMAKE_SOURCE_DIR}/include/cython/")
add_extension(bfs)
add_extension(pagerank)
add_extension(sssp)
add_extension(wcc)
add_extension(lcc)
add_extension(lpa)

add_v2procedure(bfs)
add_v2procedure(lcc)
add_v2procedure(wcc)
add_v2procedure(sssp)
add_v2procedure(lpa)
add_v2procedure(pagerank)
